import * as THREE from "three";
import {
  vertexShader,
  fragmentShader,
  vertexSphere,
  fragmentSphere,
} from './shaders/a'
import { createGeometry } from "./geometry";
import { createMaterial } from "./materials";
// import { dToRArr } from './util'
// import {onFrame} from "../canvas";

export default function createMesh({
  animate,

  positionX,
  positionY,
  positionZ,
  // rotationX,
  // rotationY,
  // rotationZ,

  type,
  color1,
  color2,
  color3,
  uTime,
  uSpeed,
  uDensity,
  uStrength,
  uFrequency,
  uAmplitude,
}) {
  const geometry = createGeometry(type);
  const material = createMaterial({
    animate,
    uniforms: {
      colors: [color1,color2, color3],
      uTime,
      uSpeed,

      uLoadingTime: 1,

      uNoiseDensity: uDensity,
      uNoiseStrength: uStrength,
      uFrequency,
      uAmplitude,
      uIntensity: 0.5
    },
    vertexShader: type === 'sphere' ? vertexSphere : vertexShader,
    fragmentShader: type === 'sphere' ? fragmentSphere : fragmentShader,
    onInit(material1) {
      console.log(material1);
    }
  });

  const mesh = new THREE.Mesh( geometry, material );

  mesh.position.set(positionX, positionY, positionZ);
  mesh.rotation.set(0, 0, Math.PI / 2);
  // let i = 0;
  // onFrame(()=>{
  //     i = i+1;
  //
  //     mesh.rotation.set(0, 0, Math.PI / 180 * i);
  // }, 1000)
  // setInterval(()=> {
  //     i = i+1;
  //
  //     mesh.rotation.set(0, 0, Math.PI / 180 * i);
  // }, 1000)
  // mesh.rotation.set(...dToRArr([rotationX, rotationY, rotationZ]));
  // setTimeout(()=> {
  //     mesh.rotation.set(...dToRArr([rotationX, rotationY, rotationZ]));
  // }, 1000)

  return mesh;
}
